﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BanVeXemPhim_Presentation
{
    public partial class UserControlChonPhim : UserControl
    {
        public UserControlChonPhim()
        {
            InitializeComponent();
        }

        public delegate void ChonPhim(PhimDTO phim);
        public event ChonPhim SuKienChonPhim;

        private PhimDTO[] _dsPhim;
        private int _nPhim;

        public PhimDTO[] DsPhim
        {
            get { return _dsPhim; }
            set
            {
                _dsPhim = value;
                if (DsPhim != null)
                {
                    _nPhim = _dsPhim.Length;
                    CapNhatDsPhim();
                }

            }
        }

        public int NPhim
        {
            get { return _nPhim; }
            set
            {
                _nPhim = value;
            }
        }

        private void UserControlChonPhim_Load(object sender, EventArgs e)
        {
            CapNhatDsPhim();
        }

        //Load user control phim lên flowlayoutcontrol.
        public void CapNhatDsPhim()
        {
            if (_nPhim > 0)
            {
                foreach(PhimDTO var in DsPhim)
                {
                    UserControlPhim userControlPhim = new UserControlPhim();
                    userControlPhim.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    userControlPhim.Phim = var;
                    userControlPhim.ClickEvent+=new UserControlPhim.ClickBook(XuLyChonPhim);
                    userControlPhim.Size = new System.Drawing.Size(124, 164);
                    this.flowLayoutPanel1.Controls.Add(userControlPhim);
                }
            }
        }

        public void XuLyChonPhim(PhimDTO phim)
        {
            if (SuKienChonPhim != null)
            {
                SuKienChonPhim(phim);
            }
        }



    }
}
